﻿using Bouyei.GeoCore.Geometries;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bouyei.GeoCore.GeoParsers.GeoJson
{
    public class GeoJsonPoint<T, Point>
        : GeoJsonObject<T, Point> where Point : PointArray
    {
        public GeoJsonPoint() { }

        public GeoJsonPoint(Feature<T, Point>[] features)
            : base()
        {
            this.features = features;
        }
    }

    public class GeoJsonPoint : GeoJsonGeometry
    {
        public double[] coordinates { get; set; }

        public GeoJsonPoint()
        {

        }

        public GeoJsonPoint(string jsonString)
        {
            var geo = jsonConvert.ConvertTo<GeoJsonPoint>(jsonString);
            this.coordinates = geo.coordinates;
            this.type = geo.type;
        }

        public GeoJsonPoint(Geometry geometry)
        {
            this.Geometry = geometry;
        }

        public Geometry ToGeometry()
        {
            var geo = new Geometry(new Coordinate()
            {
                X = coordinates[0],
                Y = coordinates[1],
                Z = coordinates.Length == 3 ? coordinates[2] : 0
            });

            geo.GeometryType = GeometryType;

            return geo;
        }

        public string FromGeometry()
        {
            this.type = getType();
            var coord = Geometry.GetGemoetry(0)[0][0];
            this.coordinates = new double[] { coord.X, coord.Y };

            return jsonConvert.ConvertFrom(this);
        }
    }
}
